Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: Filter by custom fields in graph ql #18012

Conversation

christophbeberweil
Copy link

Works on : #7598

I worked on issue #7598 and made progress. Unfortunaltely, I hit some roadblocks and none of the maintainers were available to answer my questions. I open this merge request with my partial solution so that it might be of use for the project in the future.

I utilized autotype_decorator, which is used to communicate the filterset to graphql, in order to add CustomField entries with the same logic applied as in netbox.filtersets.NetBoxModelFilterSet. The code calls create_attribute_and_function for each custom field of the current model. This successfully adds a new filter to GraphQL, which is recognized in the backend. Unfortunately, there are still some problems:

  • The generated Filter itereates over the filter argument, so a filter by "Foo" filters by "F" OR "o" OR "o", which is not the desired functionality.
  • Additionally, filters on non-iterable datatypes such as int do not work.
  • After adding a new CustomField, the server needs to be restarted in order for GraphQL to be aware of the new field. Since GraphQL is a schema-based tool, it is not clear if the restart requirement can be avoided.
  • The lints in the GraphIQL-Frontend do not recognize the new CustomField filter. Nevertheless, applying the filter will lead to a change in the output, so it is recognized by the server. For instance, after creating a custom field a_string on Device, the following graphql statement can be used to filter the devices, but GraphIQL does not know of cf_a_string:
{
 device_list(filters: {cf_a_string: "a"}) {
  id
  name
  custom_fields
  local_context_data
  device_type {
   id
   display
   slug
  }
 }
}

@christophbeberweil christophbeberweil marked this pull request as draft November 14, 2024 09:28
@jeremystretch
Copy link
Member

@christophbeberweil are you still planning to work on this?

@christophbeberweil
Copy link
Author

@jeremystretch Unfortunately not, since I was not able to obtain answers for my questions from you or the community.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants